package org.jxht.web.api;

import org.jxht.dto.AdminDto;
import org.jxht.service.AdminServie;
import org.jxht.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by huang on 2017/3/20 0020.
 */
@Controller
@RequestMapping("JxhtWeb/AdminController")
public class AdminController {

    @Autowired
    private AdminServie adminServie;

    @RequestMapping(value = "/{requestId}/addAdminInfo")
    public String addAdminInfo(@PathVariable(value = "requestId")int requestId,
                               @RequestParam(value = "requestJson")String requestJson){
        List<AdminDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,AdminDto.class);
        for(AdminDto dto:dtos){
            adminServie.insertAdminService(dto);
        }
        return "SUCCESS";
    }

    @RequestMapping(value = "/{requestId}/changeAdminInfo")
    public String changeAdminInfo(@PathVariable(value = "requestId")int requestId,
                                  @RequestParam(value = "requestJson")String requestJson){
        List<AdminDto> dtos = GsonUtil.parseJsonArrayWithGson(requestJson,AdminDto.class);
        for(AdminDto dto:dtos){
            adminServie.updataAdminService(dto);
        }
        return "SUCCESS";
    }

    @RequestMapping(value = "/{requestId}/deleteAdminInfo")
    public String deleteAdminInfo(@PathVariable(value = "requestId")int requestId){
        adminServie.deleteAdminService(new AdminDto(requestId));
        return "SUCCESS";
    }
}
